package com.ruoyi.web.controller.storeEmployeeCommission;


import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CommissionRuleOperationLog;
import com.ruoyi.system.service.ICommissionRuleOperationLogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 提成规则操作记录（含完整规则字段+联系电话）Controller
 *
 * @author ruoyi
 * @date 2025-05-18
 */
@Api(tags="提成规则操作记录")
@RestController
@RequestMapping("/system/commissionRuleOperationLog")
public class CommissionRuleOperationLogController extends BaseController
{
    @Autowired
    private ICommissionRuleOperationLogService commissionRuleOperationLogService;

    /**
     * 查询提成规则操作记录列表
     */
    @ApiOperation("查询提成规则操作记录列表")
    @PreAuthorize("@ss.hasPermi('system:log:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam(required = false) String operationType, @RequestParam(required = false) String commissionType, @RequestParam(required = false) Date operationStartTime,
                              @RequestParam(required = false) Date operationEndTime, @RequestParam(required = false) String operatorName)
    {
        startPage();
        List<CommissionRuleOperationLog> list = commissionRuleOperationLogService.selectCommissionRuleOperationLogListByConditions(operationType,commissionType,operationStartTime,operationEndTime,operatorName);
        return getDataTable(list);
    }

    /**
     * 导出提成规则操作记录列表
     */
    @ApiOperation("导出提成规则操作记录列表")
    @PreAuthorize("@ss.hasPermi('system:log:export')")
    @Log(title = "提成规则操作记录（含完整规则字段+联系电话）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestParam(required = false) String operationType, @RequestParam(required = false) String commissionType, @RequestParam(required = false) Date operationStartTime,
                       @RequestParam(required = false) Date operationEndTime, @RequestParam(required = false) String operatorName)
    {
        List<CommissionRuleOperationLog> list = commissionRuleOperationLogService.selectCommissionRuleOperationLogListByConditions(operationType,commissionType,operationStartTime,operationEndTime,operatorName);
        ExcelUtil<CommissionRuleOperationLog> util = new ExcelUtil<CommissionRuleOperationLog>(CommissionRuleOperationLog.class);
        util.exportExcel(response, list, "提成规则操作记录（含完整规则字段+联系电话）数据");
    }

    /**
     * 通过id获取提成规则操作记录详细信息
     */
    @ApiOperation("通过id获取提成规则操作记录详细信息")
    @PreAuthorize("@ss.hasPermi('system:log:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(commissionRuleOperationLogService.selectCommissionRuleOperationLogById(id));
    }

    /**
     * 新增提成规则操作记录
     */
    @ApiOperation("新增提成规则操作记录")
    @PreAuthorize("@ss.hasPermi('system:log:add')")
    @Log(title = "提成规则操作记录（含完整规则字段+联系电话）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommissionRuleOperationLog commissionRuleOperationLog)
    {
        return toAjax(commissionRuleOperationLogService.insertCommissionRuleOperationLog(commissionRuleOperationLog));
    }

    /**
     * 修改提成规则操作记录
     */
    @ApiOperation("修改提成规则操作记录")
    @PreAuthorize("@ss.hasPermi('system:log:edit')")
    @Log(title = "提成规则操作记录（含完整规则字段+联系电话）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommissionRuleOperationLog commissionRuleOperationLog)
    {
        return toAjax(commissionRuleOperationLogService.updateCommissionRuleOperationLog(commissionRuleOperationLog));
    }

    /**
     * 通过id批量删除提成规则操作记录
     */
    @ApiOperation("通过id批量删除提成规则操作记录")
    @PreAuthorize("@ss.hasPermi('system:log:remove')")
    @Log(title = "提成规则操作记录（含完整规则字段+联系电话）", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(commissionRuleOperationLogService.deleteCommissionRuleOperationLogByIds(ids));
    }
}

